/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.rocketmq.store.timer;

/**
 * Represents a slot of timing wheel. Format:
 * ┌────────────┬───────────┬───────────┬───────────┬───────────┐
 * │delayed time│ first pos │ last pos  │    num    │   magic   │
 * ├────────────┼───────────┼───────────┼───────────┼───────────┤
 * │   8bytes   │   8bytes  │  8bytes   │   4bytes  │   4bytes  │
 * └────────────┴───────────┴───────────┴───────────┴───────────┘
 *
 * 前八个字节：延迟时间
 * 之后八字节：第一个位置
 * 之后八字节：最后一个位置
 * 之后四字节：数字
 * 最后四字节：魔幻数字（保留，未使用）
 *
 * 数据在缓冲中的起始偏移量，和在缓冲中的最后偏移量，指定该Slot记录的数据。该数据延迟多长时间，num是什么？
 *
 */
public class Slot {
    public static final short SIZE = 32;
    /**
     * 延迟时间毫秒值
     */
    public final long timeMs; //delayed time

    /**
     * 第一个位置
     */
    public final long firstPos;

    /**
     * 最后一个位置
     */
    public final long lastPos;

    /**
     * 个数
     */
    public final int num;

    /**
     * 现在不用，保留。
     * 魔幻数字
     */
    public final int magic; //no use now, just keep it

    public Slot(long timeMs, long firstPos, long lastPos) {
        this.timeMs = timeMs;
        this.firstPos = firstPos;
        this.lastPos = lastPos;
        this.num = 0;
        this.magic = 0;
    }

    public Slot(long timeMs, long firstPos, long lastPos, int num, int magic) {
        this.timeMs = timeMs;
        this.firstPos = firstPos;
        this.lastPos = lastPos;
        this.num = num;
        this.magic = magic;
    }
}
